package com.soft.javase.day06.regex;

import java.util.Scanner;

/**
 * @author yzh
 * @desc TODO
 * @date 2025/4/24
 */
public class ValidPhoneNumber {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入手机号：");
        String phoneNumber = sc.nextLine().trim();

        if (phoneNumber.length() != 11) {
            System.out.println("手机号位数不正确，必须是11位！");
            return;
        }

        if (!isAllDigit(phoneNumber)) {
            System.out.println("手机号必须全部是数字！");
            return;
        }

        boolean isLianghao = isLianghao(phoneNumber);

        System.out.println("手机号验证通过！");
        System.out.println("是否为靓号：" + (isLianghao ? "是" : "否"));

        sc.close();
    }

    public static boolean isAllDigit(String phoneNumber) {
        for (int i = 0; i < phoneNumber.length(); i++) {
            if (!Character.isDigit(phoneNumber.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    public static boolean isLianghao(String phoneNumber) {
        char lastDigit = phoneNumber.charAt(phoneNumber.length() - 1);
        for (int i = 1; i <= 2; i++) {
            if (phoneNumber.charAt(phoneNumber.length() - 1 - i) != lastDigit) {
                return false;
            }
        }
        return true;
    }
}
